<?php

//补全其他的
/*
********9、PHP操作MySQL********
*/
$serve = 'localhost:3306';
$username = 'root';
$password = '';
$dbname = 'student';
//连接数据库
$link = mysqli_connect(
    $serve,$username,$password,
    $dbname);
// 设置数据库字符集
mysqli_set_charset($link,'UTF8'); 


//查询数据库
$result = mysqli_query($link,
      'select * from student');
// 获取数据 
$data = mysqli_fetch_all(
    $result,MYSQLI_ASSOC); 
// 释放结果集 
mysqli_free_result($result); 

?>
<html>
<head>
<title>学生列表</title>
</head>
<body>
<h4>学生列表</h4>
<a href="add.php">添加学生</a>
<table border=1>
<tr>
    <th>学号</th> 
    <th>姓名</th>
    <th>性别</th>
    <th>班级</th>
    <th>操作</th>
</tr>
<?php
    foreach($data as $one){
        echo "<tr>";
        foreach($one as $key=>$value){
            if($key!="id")
            echo "<td>".$value."</td>";
        }
        echo '<td><a href="del.php?id='.$one["id"].'">删除</a>';
        echo ' <a href="edit.php?id='.$one["id"].'">编辑</a></td>';
        echo "</tr>";
    }
?>
</table>
</body>
</html>